<?php
/**
 * Member.php
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: http://www.niushop.com.cn
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 * @author : niuteam
 * @date : 2015.1.17
 * @version : v1.0.0.0
 */
namespace app\admin\controller;

use data\model\NsCoinFundModel;
use data\model\NsCoinTradeModel;
use data\model\NsGoodsModel;
use data\model\NsGoodsSkuModel;
use data\model\NsTokenModel;
use data\model\NsTokenViewModel;
use data\model\UserModel;
use data\service\Mine\Mine as MineService;
use data\service\Config;
use data\service\Member;

/**
 * 挖抗管理
 *
 * @author Administrator
 *        
 */
class Mine extends BaseController
{

    private $arrXing,$numbXing;

    private $arrMing,$numbMing;
    public function __construct()
    {
        parent::__construct();
        $this->getXingList();

        $this->getMingList();
    }

    //币价格管理
    public function coinpricelist()
    {
        if (request()->isAjax()) {
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $condition = array();
            $mine = new MineService();
            $list = $mine->getCoinPriceList($page_index, $page_size, $condition, $order = 'ncp.cur_time desc', $field = '*');
            return json($list);
        }
        return view($this->style . 'Mine/CoinPriceList');
        //return 1;

    }


    //解封申请删除
    public function ublockDel()
    {
        $id = request()->post("id", 0);
        trace("ID:".$id,"debug");
        if($id)
        {
            $mine = new MineService();
            $res = $mine->delUblockRecords($id);
            return AjaxReturn($res);
        }
    }

    // 会员投诉回复
    // 回复会员一个投诉记录
    public function apply_complain()
    {
        $cid = request()->post("cid", 0);
        $replay = request()->post("replay", "");
        if($cid)
        {
            $mine = new MineService();
            $res = $mine->modifyTradeComplain($cid,$replay);
            return AjaxReturn($res);
        }
    }

    // 会员投诉删除
    public function tradeComplainDel()
    {
        $id = request()->post("id", 0);
        // trace("ID:".$id,"debug");
        if($id)
        {
            $mine = new MineService();
            $res = $mine->delTradeComplain($id);
            return AjaxReturn($res);
        }
    }


    // 会员矿机删除
    public function runMillDel()
    {
        $id = request()->post("id", 0);
        trace("ID:".$id,"debug");
        if($id)
        {
            $mine = new MineService();
            $res = $mine->delRunMillPrice($id);
            return AjaxReturn($res);
        }
    }


    // 客服删除
    public function kefuDel()
    {
        $id = request()->post("id", 0);
        trace("ID:".$id,"debug");
        if($id)
        {
            $mine = new MineService();
            $res = $mine->delKefu($id);
            return AjaxReturn($res);
        }
    }

    // 删除一个买币规则
    public function buyCoinSendDel()
    {
        $id = request()->post("id", 0);
        if($id)
        {
            $mine = new MineService();
            $res = $mine->buyCoinSendDel($id);
            return AjaxReturn($res);
        }
    }

    // 矿机删除
    public function millDel()
    {
        $id = request()->post("id", 0);
        trace("ID:".$id,"debug");
        if($id)
        {
            $mine = new MineService();
            $res = $mine->delMillPrice($id);
            return AjaxReturn($res);
        }
    }

    //币价删除
    public function coinPriceDel()
    {
        $id = request()->post("id", 0);
        // $this->success('交易记录删除成功', 'mine/coinPriceList');

        trace("ID:".$id,"debug");
        if($id)
        {
            $mine = new MineService();
            $res = $mine->delCoinPrice($id);
            return AjaxReturn($res);
        }
    }

    //添加币价
    public function addCoinPrice()
    {
        $mine = new MineService();
        if(request()->isAjax()){
            $cur_price = request()->post("cur_price",0);
            $sell_price = request()->post("sell_price",0);
            $cur_time = request()->post("cur_time",'');

            // 更新商品价格
            /*
            if(date('Y-m-d',time()) == $cur_time){
                $this->updateGoodsPrice(34,10,$cur_price);
                $this->updateGoodsPrice(35,20,$cur_price);
                $this->updateGoodsPrice(36,50,$cur_price);
                $this->updateGoodsPrice(37,100,$cur_price);
                $this->updateGoodsPrice(38,500,$cur_price);
                $this->updateGoodsPrice(39,5,$cur_price);
            }
            */

            $res = $mine->addCoinPrice($cur_price,$cur_time,$sell_price);
            return AjaxReturn($res);
        }
        return view($this->style.'Mine/addCoinPrice');
    }


    public function updateGoodsPrice($goods_id,$weight,$cur_price)
    {
        $goods_price =  $weight *  $cur_price;

        $goods = new NsGoodsModel();

        $goods->save(['price'=>$goods_price,'promotion_price'=>$goods_price,'goods_rank_point'=>$goods_price],['goods_id'=>$goods_id]);

        $sku = new NsGoodsSkuModel();
        $sku->save(['price'=>$goods_price,'promote_price'=>$goods_price],['goods_id'=>$goods_id]);


    }

    //添加交易记录
    public function addCoinTrade()
    {
        $mine = new MineService();
        if(request()->isAjax()){
            $post_uid = request()->post("post_uid",0);
            $trade_type = request()->post("trade_type",'');
            $trade_status = request()->post("trade_status",'');

            $coin_count = request()->post("coin_count",0);
            $coin_price = request()->post("coin_price",'');
            $add_time = request()->post("add_time",0);
            $trade_time = request()->post("trade_time",'');
            $finish_time = request()->post("finish_time",0);
            $res = $mine->addCoinTrade($post_uid,$trade_type,$trade_status,$coin_count,$coin_price,$add_time,$trade_time,$finish_time);
            return AjaxReturn($res);
        }
        return view($this->style.'Mine/addCoinTrade');
    }


    public function releaseFrozenCoinAll(){

        $order_by = request()->post("order_by", 'salary');
        $asc = request()->post("asc", 'desc');
        $page_index = request()->post("page_index", 1);
        $page_size = request()->post('page_size', PAGESIZE);
        $condition = array();
        $order = $order_by." ".$asc;
        $today_time = strtotime(date('Y-m-d'));
        $condition['ma.salary'] = ['>',0];
        //$condition['ma.last_release_time'] = ['neq',$today_time];
        trace($condition,"debug");
        $mine = new MineService();
        $list = $mine->getMemberAccountList($page_index, $page_size, $condition, $order, $field = '*');

        foreach ($list['data'] as $v) {
            trace($v['id'],"debug");
            $mine = new MineService();
            $res = $mine->releaseFrozenCoin($v['id']);
        }
        return AjaxReturn(1);
    }


    // 手动释放
    public function releaseFrozenCoin(){
        $id = request()->post("id", 0);
        trace("ID:".$id,"debug");
        if($id)
        {
            $mine = new MineService();
            $res = $mine->releaseFrozenCoin($id);
            return AjaxReturn($res);
        }
    }



    // 金额排行
    public function memberAccountList()
    {
        if (request()->isAjax()) {
            $order_by = request()->post("order_by", 'salary');
            $asc = request()->post("asc", 'desc');
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $condition = array();
            $order = $order_by." ".$asc;
            $mine = new MineService();
            $list = $mine->getMemberAccountList($page_index, $page_size, $condition, $order, $field = '*');
            return json($list);
        }
        return view($this->style . 'Mine/memberAccountList');
    }

    //众筹管理
    public function fundlist()
    {
        if (request()->isAjax()) {
            $trade_status = request()->post("trade_status", '');
            $post_user_tel = request()->post("post_user_tel", '');
            $op_user_tel = request()->post("op_user_tel", '');

            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $condition = array();
            if($trade_status != '')
            {
                $condition['trade_status'] = $trade_status;
            }

            if($post_user_tel)
            {
                $uid = $this->user->getUserInfoByMobile($post_user_tel)["uid"];
                if($uid)
                {
                    $condition['post_uid']=$uid;
                }
            }
            if($op_user_tel)
            {
                $uid = $this->user->getUserInfoByMobile($op_user_tel)["uid"];
                $condition['op_uid']=$uid;
            }
            $mine = new MineService();
            trace($condition,"debug");
            $list = $mine->getCoinFundList($page_index, $page_size, $condition, $order = 'nft.fid desc', $field = '*');


            return json($list);
        }


        // 获取首码用户
        $member = new \data\service\Member();
        $condition["su.desc"] = -1;
        $user_list = $member->getMemberList(1,0, $condition);

        //trace($user_list,"debug");

        $this->assign("user_list", $user_list["data"]);
        //$this->infrastructureChildMenu(1);
        return view($this->style . 'Mine/fundList');
    }


    // 匹配众筹订单
    public function saveMatchFund()
    {
        $fid = request()->post("fid", '');
        $op_uid = request()->post("op_uid", '');
        $fund_model = new NsCoinFundModel();

        $info = $fund_model->getInfo(['fid'=>$fid],"*");
        if($info["trade_status"] == 0)
        {
            $res = $fund_model->save(['trade_status'=>1,'trade_time'=>time(),'op_uid'=>$op_uid],['fid'=>$fid]);
            $member = new \data\service\Member();
            $m_info = $member->getUserInfoByUid($info["uid"]);
            $params['mobile'] = $m_info["user_tel"];
            $params['msg'] = '订单已经匹配好了卖家，请您及时登录APP操作';
            $result = runhook('Notify', 'tradeSmsNotify', $params);
        }




        return 1;
    }


    // 立即匹配订单
    public function sellCoinTrade()
    {

        $user = new UserModel();
        $list = $user->getQuery(['arrive'=>10000],"uid","uid asc");

        if($list)
        {
            $i = array_rand($list);
            trace($list[$i]['uid'],'debug');
            $op_uid = $list[$i]['uid'];
            if($op_uid)
            {
                $tid = request()->post("tid", 0);
                $mine = new MineService();
                $mine->backSellCoinTrade($op_uid,$tid);
            }
            //return AjaxReturn(1);

        }

        return AjaxReturn(1);
    }


    // 优先订单
    public function upCoinTrade()
    {
        $tid = request()->post("tid", 0);
        $coin_trade = new NsCoinTradeModel();
        $data = array(
            'trade_type' => 1
        );
        $res = $coin_trade->save($data,['tid'=> $tid]);
        return AjaxReturn($res);
    }

    //交易管理
    public function tradelist()
    {

        if (request()->isAjax()) {
            $trade_status = request()->post("trade_status", '');
            $post_user_tel = request()->post("post_user_tel", '');
            $coin_count_ser = request()->post("coin_count_ser", '-1');
            $tid_sort = request()->post("tid_sort", '-1');

            $op_user_tel = request()->post("op_user_tel", '');

            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $condition = array();
            if($trade_status != '')
            {
                $condition['trade_status'] = $trade_status;
            }
            if($coin_count_ser != -1)
            {
                $condition['coin_count'] = $coin_count_ser;
            }
            

            $member = new Member();

            if($post_user_tel)
            {
               $uid = $member->getUserInfoByMobile($post_user_tel)["uid"];
               if($uid)
               {
                   $condition['post_uid']=$uid;
               }
            }
            if($op_user_tel)
            {
                $uid = $member->getUserInfoByMobile($op_user_tel)["uid"];
                if($uid and $uid != 60912)
                {
                    $condition['op_uid']=$uid;
                }
            }
            else
            {
                $condition['op_uid'] = ["neq",60912];
            }
            $mine = new MineService();


            if($tid_sort == 1)
            {

                $condition['add_time'] = ["gt",strtotime(date('Y-m-d'))];
                $list = $mine->getCoinTradeList($page_index, $page_size, $condition, $order = 'nct.tid asc', $field = '*');
            }
            else
            {

                $list = $mine->getCoinTradeList($page_index, $page_size, $condition, $order = 'nct.tid desc', $field = '*');

            }


            return json($list);
        }


        $config = new Config();
        $key = "COUNT_RATE";
        $info = $config->getCacheConfig(0, $key);
        $count_rate = $info["value"];

        $count_list = explode (',', $count_rate);
        $this->assign("count_list", $count_list);
        //$this->infrastructureChildMenu(1);
        return view($this->style . 'Mine/TradeList');
    }


    // 子菜单
    public function infrastructureChildMenu($tag)
    {
        $child_menu_list = array(
            array(
                'url' => "Mine/tradeList",
                'menu_name' => "全部",
                "active" => 0,
                "tag" => 1
            ),
            array(
                'url' => "Mine/tradeList?trade_status=0",
                'menu_name' => "挂单中",
                "active" => 0,
                "tag" => 2
            ),
            array(
                'url' => "Mine/tradeList?trade_status=1",
                'menu_name' => "待付款",
                "active" => 0,
                "tag" => 2
            ),
            array(
                'url' => "Mine/tradeList?trade_status=2",
                'menu_name' => "待收款",
                "active" => 0,
                "tag" => 2
            ),
            array(
                'url' => "Mine/tradeList?trade_status=3",
                'menu_name' => "已完成",
                "active" => 0,
                "tag" => 2
            )
        );

        if (! empty($tag)) {
            foreach ($child_menu_list as $k => $v) {
                if ($v['tag'] == $tag) {
                    $child_menu_list[$k]["active"] = 1;
                }
            }
        }
        $this->assign("child_menu_list", $child_menu_list);
    }


    /**
     * 客服列表
     */
    public function kfList()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $list = $mine->getKfList($page_index, $page_size);
            return $list;
        }
        return view($this->style . 'Mine/kfList');
    }



    /**
     * 买币活动逻辑列表
     */

    public function buyCoinSendList()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $list = $mine->getBuyCoinSendList($page_index, $page_size);
            return $list;
        }
        return view($this->style . 'Mine/buyCoinSendList');
    }


    /**
     * 矿机等级列表
     */
    public function millLevelList()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $list = $mine->getMillLevelList($page_index, $page_size);
            return $list;
        }
        return view($this->style . 'Mine/millLevelList');
    }


    // 添加客服
    public function addKefu()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $kf_name = request()->post("kf_name", '');
            $kf_qr = request()->post("mill_pic", '');
            $kf_sort = request()->post("kf_sort", 0);
            $kf_desc = request()->post("kf_desc", 0);
            $status = request()->post("status", 0);
            $res = $mine->addKefu($kf_name, $kf_qr, $kf_sort, $status,$kf_desc);
            return AjaxReturn($res);

        }
        return view($this->style . 'Mine/addKefu');
    }


    // 添加买币赠送矿机
    public function addCoinSend()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $buy_coin_count = request()->post("buy_coin_count", 0);
            $give_small = request()->post("give_small", '');
            $give_middle = request()->post("give_middle", 0);
            $give_large = request()->post("give_large", 0);
            $give_super = request()->post("give_large", 0);
            $res = $mine->addBuyCoinSend($buy_coin_count, $give_small, $give_middle, $give_large,$give_super);
            return AjaxReturn($res);

        }
        return view($this->style . 'Mine/addCoinSend');
    }

    // 添加矿机
    public function addMill()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $level_name = request()->post("level_name", '');
            $mill_pic = request()->post("mill_pic", '');

            $day_product = request()->post("day_product", 0);
            $total_product = request()->post("total_product", 0);
            $status = request()->post("status", 0);
            $res = $mine->addMill($this->instance_id, $level_name, $day_product, $total_product, $status,$mill_pic);
            return AjaxReturn($res);

        }
        return view($this->style . 'Mine/addMill');
    }


    // 会员投诉列表
    public function tradeComplainList()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $list = $mine->getTradeComplainList($page_index, $page_size,[],"ncc.cid desc");
            return $list;
        }
        return view($this->style . 'Mine/tradeComplainList');
    }


    // 修改购币奖励规则
    public function sendCoinModify()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $id = request()->post("id", 0);
            $give_small = request()->post("give_small", '');
            $give_middle = request()->post("give_middle", 0);
            $give_large = request()->post("give_large", 0);
            $give_super = request()->post("give_super", 0);
            $update_level = request()->post("update_level", 0);
            $give_parent = request()->post("give_parent", 0);
            $res = $mine->modifyBuyCoinSend($id,$give_small,$give_middle,$give_large,$give_super,$update_level,$give_parent);
            return AjaxReturn($res);
        }
        $id = request()->get("id", 0);
        $info = $mine->getBuyCoinSendInfo($id);
        $this->assign('info', $info);
        return view($this->style . 'Mine/sendCoinModify');
    }


    // 修改矿机
    public function millLevelModify()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $level_id = request()->post("level_id", 0);
            $level_name = request()->post("level_name", '');
            $day_product = request()->post("day_product", 0);
            $total_product = request()->post("total_product", 0);
            $hour_product = request()->post("hour_product", 0);
            $price = request()->post("price", 0);
            $add_hash = request()->post("add_hash", 0);
            $all_day = request()->post("all_day", 0);
            $mill_pic = request()->post("mill_pic", '');
            $can_buy = request()->post("can_buy", 0);
            $status = request()->post("status", 0);
            $product_give = request()->post("product_give", '');
            $product_desc = request()->post("product_desc", '');

            //$day_product = $total_product / $all_day;
            //$hour_product = $total_product / $all_day / 24;

            $res = $mine->modifyMill($level_id,$level_name,$day_product,$total_product,$status,$mill_pic,$hour_product,$price,$add_hash,$all_day,$can_buy,$product_give,$product_desc);
            return AjaxReturn($res);
        }
        $level_id = request()->get("level_id", 0);
        $info = $mine->getMillLevelInfo($level_id);
        $this->assign('info', $info);
        return view($this->style . 'Mine/millLevelModify');
    }

    // 会员矿机列表
    public function memberMillList()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $level_id = request()->post('level_id', -1);
            $status = request()->post('status', -1);
            $condition = [];
            if($status != -1)
            {
                $condition["nrm.status"] = $status;
            }
            if($level_id != -1)
            {
                $condition["nrm.level_id"] = $level_id;
            }
            trace($condition);

            $list = $mine->getRunMillList($page_index, $page_size,$condition,"run_mill_id desc");
            return $list;
        }
        // 获取会员矿机等级
        $page_index = request()->post("page_index", 1);
        $page_size = request()->post('page_size', 0);
        $list = $mine->getMillLevelList($page_index, $page_size);
        $this->assign("mill_level_list", $list["data"]);

        return view($this->style . 'Mine/memberMillList');
    }

    // 会员申请解封列表
    public function ublockList()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $list = $mine->getUblockList($page_index, $page_size);
            return $list;
        }
        return view($this->style . 'Mine/ublockList');
    }


    // 确认收款众筹订单
    public function recFundTrade()
    {
        $fid = request()->post("fid", 0);
        $fund_model = new NsCoinFundModel();
        $info = $fund_model->getInfo(["fid"=>$fid],"*");
        $uid = $info['uid'];
        $total_price = $info['total_price'];
        if($info["trade_status"] == 0)
        {
            $res = $fund_model->save(['trade_status' => 3,'finish_time'=>time()],['fid'=>$fid]);
            // 为会员发放推荐奖金
            $mine = new \data\service\Mine\Mine();
            $mine->sendFundSalary($uid,$total_price);
        }
        return AjaxReturn($res);
    }


    // 删除众筹订单
    public function deleteFundTrade()
    {
        $fid = request()->post("fid", 0);
        $fund_model = new NsCoinFundModel();
        //trace($fid,"debug");
        //$info = $fund_model->getInfo(["fid"=>$fid],"*");
        //$uid = $info["uid"];
        //$retval = $this->user->changeUserStatus($uid,"众筹传假图",0);
        $res = $fund_model->save(['trade_status' => -1,'finish_time'=>time()],['fid'=>$fid]);
        return AjaxReturn($res);
    }

    // 删除订单
    public function deleteCoinTrade()
    {
        $tid = request()->post("tid", 0);
        $i = request()->post("i", 0);
        $coin_trade = new NsCoinTradeModel();

        if($i == 1)
        {
            $info = $coin_trade->getInfo(["tid"=>$tid],"*");
            $op_uid = $info["op_uid"];
            $post_uid = $info["post_uid"];
            $coin_count = $info["coin_count"];
            $retval = $this->user->changeUserStatus($post_uid,"传假图",0);
            if($op_uid)
            {
                $member = new \data\service\Member();

                $member_info = $member->getMemberDetail($op_uid);
                $rate = $member_info["level_info"]["goods_discount"]; // 等级手续费
                $retval = $member->addMemberAccount(0, 1, $op_uid, $coin_count*(1+$rate), '点对点交易对方违规返还' );
                $retval = $member->addMemberAccount(0, 2, $op_uid, $coin_count*(1+$rate), '点对点交易对方违规返还');

            }
            $this->changeTradeStatus($tid);
        }
        else
        {

            $res = $coin_trade->destroy(['tid'=>$tid]);
            return AjaxReturn($res);
        }

    }

    // 违规订单状态更改
    public function changeTradeStatus($tid)
    {
        $coin_trade = new NsCoinTradeModel();
        $data = array(
            'trade_status' => -1,
            'finish_time' => time()
        );
        $coin_trade->save($data,['tid'=> $tid]);
    }


    function actAddTrade()
    {
        $buy_count = request()->post('coin_count', 0);
        $user_tel = request()->post('user_tel', '15961466092');
        $dis_user_tel = request()->post('dis_user_tel', 0);
        $real_name = request()->post('real_name', 0);
        $time = request()->post('time', 0);
        $level_id = request()->post('level_id', 6);

        //trace("购买数量：".$buy_count,"debug");
        if($real_name == 0)
        {
            $real_name = $this->getName(2);
            trace("真实姓名：".$real_name,"debug");
        }
        if($dis_user_tel == 0)
        {
            $dis_user_tel = $this->randMobile()[0];
        }

        if($time == 0)
        {
            $time = time();
        }

        $member = new \data\service\Member();
        $info = $member->getUserInfoByMobile($user_tel);

        if($info){
            $uid = $info["uid"];
        }
        else
        {
            return AjaxReturn(YONGHU_BUCUNZAI);
        }

        if($buy_count <= 0)
        {
            return AjaxReturn(MAX_BUY);
        }

        // 获取交易配置文件
        $shop_id = 0;
        $config = new Config();
        $key = "COUNT_RATE";
        $info = $config->getCacheConfig($shop_id, $key);
        $count_rate = $info["value"];
        $count_list = explode (',', $count_rate);

        if(!in_array($buy_count, $count_list))
        {
            return AjaxReturn(TRADE_CLOSE);
        }
        $mine = new \data\service\Mine\Mine();
        $coin_price = $mine->getCurPrice();
        $post_real_name = substr_cut($real_name);
        $post_user_tel = yc_phone($dis_user_tel);
        $add_time = $time;
        $trade_no = $time.rand(1000,9999);
        $coin_trade = new NsCoinTradeModel();
        $data = array(
            'post_uid' => $uid,
            'coin_count'  => $buy_count,
            'coin_price' => $coin_price,
            'total_price' => $coin_price * $buy_count,
            'trade_status' =>0,
            'trade_type'=>0,
            'add_time'  => $add_time,
            'trade_no'  => $trade_no,
            'post_real_name' => $post_real_name,
            'post_user_tel' => $post_user_tel,
            'level_id' => $level_id
        );
        $coin_trade->save($data);


        // 增加求购币总数
        $key = "match_rate";
        $info = $config->getConfig(0, $key);
        $match_rate = $info["value"];
        $match_rate = $match_rate + $buy_count;
        $array[] = array('instance_id' => $this->instance_id,'key' => 'match_rate', 'value' => $match_rate);
        $res = $config->setConfig($array);


        return AjaxReturn(1);
    }



    /**
     * @desc 生成n个随机手机号
     * @param int $num 生成的手机号数
     * @author niujiazhu
     * @return array
     */
    function randMobile($num = 1){
        //手机号2-3为数组
        $numberPlace = array(30,31,32,33,34,35,36,37,38,39,50,51,58,59,89);
        for ($i = 0; $i < $num; $i++){
            $mobile = 1;
            $mobile .= $numberPlace[rand(0,count($numberPlace)-1)];
            $mobile .= str_pad(rand(0,99999999),8,0,STR_PAD_LEFT);
            $result[] = $mobile;
        }
        return $result;
    }



    function rndChinaName()

    {

        $this->getXingList();

        $this->getMingList();

    }

    /*

    获取姓列表

    */

    private function getXingList()

    {

        $this->arrXing=array('赵','钱','孙','李','周','吴','郑','王','冯','陈','褚','卫','蒋','沈','韩','杨','朱','秦','尤','许','何','吕','施','张','孔','曹','严','华','金','魏','陶','姜','戚','谢','邹','喻','柏','水','窦','章','云','苏','潘','葛','奚','范','彭','郎','鲁','韦','昌','马','苗','凤','花','方','任','袁','柳','鲍','史','唐','费','薛','雷','贺','倪','汤','滕','殷','罗','毕','郝','安','常','傅','卞','齐','元','顾','孟','平','黄','穆','萧','尹','姚','邵','湛','汪','祁','毛','狄','米','伏','成','戴','谈','宋','茅','庞','熊','纪','舒','屈','项','祝','董','梁','杜','阮','蓝','闵','季','贾','路','娄','江','童','颜','郭','梅','盛','林','钟','徐','邱','骆','高','夏','蔡','田','樊','胡','凌','霍','虞','万','支','柯','管','卢','莫','柯','房','裘','缪','解','应','宗','丁','宣','邓','单','杭','洪','包','诸','左','石','崔','吉','龚','程','嵇','邢','裴','陆','荣','翁','荀','于','惠','甄','曲','封','储','仲','伊','宁','仇','甘','武','符','刘','景','詹','龙','叶','幸','司','黎','溥','印','怀','蒲','邰','从','索','赖','卓','屠','池','乔','胥','闻','莘','党','翟','谭','贡','劳','逄','姬','申','扶','堵','冉','宰','雍','桑','寿','通','燕','浦','尚','农','温','别','庄','晏','柴','瞿','阎','连','习','容','向','古','易','廖','庾','终','步','都','耿','满','弘','匡','国','文','寇','广','禄','阙','东','欧','利','师','巩','聂','关','荆','司马','上官','欧阳','夏侯','诸葛','闻人','东方','赫连','皇甫','尉迟','公羊','澹台','公冶','宗政','濮阳','淳于','单于','太叔','申屠','公孙','仲孙','轩辕','令狐','徐离','宇文','长孙','慕容','司徒','司空');

        $this->numbXing = count($this-> arrXing); //姓总数

    }

    /*

    获取名列表

    */

    private function getMingList()

    {

        $this->arrMing=array('伟','刚','勇','毅','俊','峰','强','军','平','保','东','文','辉','力','明','永','健','世','广','志','义','兴','良','海','山','仁','波','宁','贵','福','生','龙','元','全','国','胜','学','祥','才','发','武','新','利','清','飞','彬','富','顺','信','子','杰','涛','昌','成','康','星','光','天','达','安','岩','中','茂','进','林','有','坚','和','彪','博','诚','先','敬','震','振','壮','会','思','群','豪','心','邦','承','乐','绍','功','松','善','厚','庆','磊','民','友','裕','河','哲','江','超','浩','亮','政','谦','亨','奇','固','之','轮','翰','朗','伯','宏','言','若','鸣','朋','斌','梁','栋','维','启','克','伦','翔','旭','鹏','泽','晨','辰','士','以','建','家','致','树','炎','德','行','时','泰','盛','雄','琛','钧','冠','策','腾','楠','榕','风','航','弘','秀','娟','英','华','慧','巧','美','娜','静','淑','惠','珠','翠','雅','芝','玉','萍','红','娥','玲','芬','芳','燕','彩','春','菊','兰','凤','洁','梅','琳','素','云','莲','真','环','雪','荣','爱','妹','霞','香','月','莺','媛','艳','瑞','凡','佳','嘉','琼','勤','珍','贞','莉','桂','娣','叶','璧','璐','娅','琦','晶','妍','茜','秋','珊','莎','锦','黛','青','倩','婷','姣','婉','娴','瑾','颖','露','瑶','怡','婵','雁','蓓','纨','仪','荷','丹','蓉','眉','君','琴','蕊','薇','菁','梦','岚','苑','婕','馨','瑗','琰','韵','融','园','艺','咏','卿','聪','澜','纯','毓','悦','昭','冰','爽','琬','茗','羽','希','欣','飘','育','滢','馥','筠','柔','竹','霭','凝','晓','欢','霄','枫','芸','菲','寒','伊','亚','宜','可','姬','舒','影','荔','枝','丽','阳','妮','宝','贝','初','程','梵','罡','恒','鸿','桦','骅','剑','娇','纪','宽','苛','灵','玛','媚','琪','晴','容','睿','烁','堂','唯','威','韦','雯','苇','萱','阅','彦','宇','雨','洋','忠','宗','曼','紫','逸','贤','蝶','菡','绿','蓝','儿','翠','烟');

        $this->numbMing = count($this-> arrMing); //名总数

    }

    private function getXing()

    {

        return $this->arrXing [mt_rand(0,$this->numbXing)];

    }

    private function getMing()

    {

        return $this->arrMing [mt_rand(0,$this->numbMing)];

    }

    public function getName($type=0)

    {

        $name = '' ;

        switch($type)

        {

            case 1: //2字

                $name = $this->getXing().$this->getMing();

                break;

            case 2: //随机2、3个字

                $name = $this->getXing().$this->getMing();

                if(mt_rand (0,100)>50)$name .= $this->getMing();

                break;

            case 3: //只取姓

                $name = $this->getXing();

                break;

            case 4: //只取名

                $name = $this->getMing();

                break;

            case 0:

            default: //默认情况 1姓+2名

                $name = $this->getXing().$this->getMing().$this->getMing();

        }

        return $name;

    }



    // 会员矿机列表
    public function memberTokenList()
    {
        $mine = new MineService();
        if (request()->isAjax()) {
            $page_index = request()->post("page_index", 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $status = request()->post('status', -1);
            $start_date = request()->post('start_date') == "" ? 0 : request()->post('start_date');
            $end_date = request()->post('end_date') == "" ? 0 : request()->post('end_date');

            $condition = [];
            $condition_acc = [];
            if($start_date != 0 && $end_date != 0){
                $condition["nt.send_time"] = [
                    [
                        ">",
                        getTimeTurnTimeStamp($start_date)
                    ],
                    [
                        "<",
                        getTimeTurnTimeStamp($end_date)
                    ]
                ];

                $condition_acc["send_time"] = [
                    [
                        ">",
                        getTimeTurnTimeStamp($start_date)
                    ],
                    [
                        "<",
                        getTimeTurnTimeStamp($end_date)
                    ]
                ];
            }elseif($start_date != 0 && $end_date == 0){
                $condition["nt.send_time"] = [
                    [
                        ">",
                        getTimeTurnTimeStamp($start_date)
                    ]
                ];
                $condition_acc["send_time"] = [
                    [
                        ">",
                        getTimeTurnTimeStamp($start_date)
                    ]
                ];
            }elseif($start_date == 0 && $end_date != 0){
                $condition["nt.send_time"] = [
                    [
                        "<",
                        getTimeTurnTimeStamp($end_date)
                    ]
                ];
                $condition_acc["send_time"] = [
                    [
                        "<",
                        getTimeTurnTimeStamp($end_date)
                    ]
                ];
            }
            if($status != -1)
            {
                $condition["nt.status"] = $status;
                $condition_acc["nt.status"] = $status;
            }
            trace($condition);
            $list = $mine->getTokenList($page_index, $page_size,$condition,"id desc");

            $token = new NsTokenViewModel();

            $total_account_all = $token->getSum($condition_acc,"total_account");
            $get_money_all = $token->getSum($condition_acc,"get_money");
            $list['total_account_all'] = $total_account_all;
            $list['get_money_all'] = $get_money_all;
            return $list;
        }
        return view($this->style . 'Mine/memberTokenList');
    }

    // 会员通令删除
    public function tokenDel()
    {
        $id = request()->post("id", 0);
        trace("ID:".$id,"debug");
        if($id)
        {
            $mine = new MineService();
            $res = $mine->delTokenDel($id);
            return AjaxReturn($res);
        }
    }
}